<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>闭包面试题</title>
</head>
<style>

</style>

<body>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
</body>
<script>
    var lis = document.querySelectorAll("li")
    for (let index = 0; index < lis.length; index++) {
        (function (j) {
            lis[index].onclick = function () {
                console.log(j);


            }
        })(index)//触发后输出永远为4


    }
</script>

</html>